package com.spring.cn.annotation.service;

import com.spring.cn.annotation.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @author liangd
 * date 2020-11-14 15:39
 * code
 */
@Service
public class UserService {

    /**
     * 应用在普通字段上
     * Qualifier("userRepositoryImpl")，里面参数是需要自动装配实例的名称，首字母要小写
     */
//    @Autowired
//    @Qualifier("userRepositoryImpl")
    private UserRepository userRepository;

    //应用在方法上
   /* @Autowired
    @Qualifier("userRepositoryImpl")
    public void setUserRepository(UserRepository userRepository) {
        this.userRepository = userRepository;
    }*/

    /**
     * 应用在参数上
     */
    @Autowired
    public void setUserRepository(@Qualifier("userRepositoryImpl")UserRepository userRepository) {
        this.userRepository = userRepository;
    }
    public void add() {
        System.out.println("UserService add...");
        userRepository.save();
    }
}
